home *** CD-ROM | disk | FTP | other *** search
/ Apple WWDC 1996 / WWDC96_1996 (CD).toast / Technology Materials / QuickTime VR / MacOS / QuickDraw™ 3D 1.0.6F4 SDK / Development / 3DMF parser / 1.0 version / MF3DPC / MFTEXTWR.C < prev    next >
Encoding:
C/C++ Source or Header  |  1995-11-07  |  3.5 KB  |  136 lines  |  [TEXT/dosa]

  1. /*==============================================================================
  2.  *
  3.  *    File:        MFTEXTWR.C
  4.  *
  5.  *    Function:    Routines for writing Text files
  6.  *
  7.  *    Version:    Metafile:    Version 1.0 3DMF files
  8.  *                Package:    Release #2 of this code
  9.  *
  10.  *    Author(s):    Rick Wong (RWW), Duet Development Corp.
  11.  *                John Kelly (JRK), Duet Development Corp.
  12.  *
  13.  *    Copyright:    (c) 1995 by Apple Computer, Inc., all rights reserved.
  14.  *
  15.  *    Change History (most recent first):
  16.  *        FB8_JRK    Segmentation
  17.  *        Fabio    Changed file name to 8 characters
  18.  *        F2K_RWW    File created.
  19.  *==============================================================================
  20.  */
  21. #include "MFTEXTWR.H"
  22.  
  23. #include <stdarg.H>        /* variable argument lists */
  24. #include <stdio.H>        /* vsprintf */
  25.  
  26. #include "MFERRORS.H"
  27. #include "MFASSERT.H"
  28. #include "MFINTOBJ.H"
  29. #include "MFTEXTST.H"
  30.  
  31. #if defined(applec) || defined(__MWERKS__) || defined(THINK_C)
  32. #pragma segment __MF3D__
  33. #endif
  34.  
  35. /*==============================================================================
  36.  *    MF3D_WriteNewLine
  37.  *
  38.  *    Add a new line to a text file (it is supposed to be readable, after all)
  39.  *==============================================================================
  40.  */
  41. MF3DErr
  42. MF3D_WriteNewLine(
  43.     MF3D_FilePtr    inMetafile)
  44. {
  45.     char                 buffer[kMF3D_MaxIndentation + 1];
  46.     unsigned int        indentation;
  47.  
  48.     if (!MF3DIsTextFormat(inMetafile->dataFormat))
  49.         return kMF3DNoErr;
  50.  
  51.     indentation = inMetafile->indent + 1;
  52.     while (indentation-- > 0)
  53.         buffer[indentation] = kMF3D_TabChar;
  54.     buffer[0] = kMF3D_NewLineChar;
  55.  
  56.     return MF3D_WriteProc(inMetafile, inMetafile->indent + 1, buffer);
  57. }
  58.  
  59. /*==============================================================================
  60.  *    MF3D_OutputText
  61.  *
  62.  *    fprintf
  63.  *==============================================================================
  64.  */
  65. MF3DErr
  66. MF3D_OutputText(MF3D_FilePtr inMetafile, const char *inFormatStr, ...)
  67. {
  68.     va_list        paramList;
  69.     int            charsWritten;
  70.     char        buffer[kMaxOutputTextBuffer];
  71.     MF3DErr        result;
  72.  
  73.     result = kMF3DNoErr;
  74.  
  75.     va_start(paramList, inFormatStr);
  76.     
  77.     charsWritten = vsprintf(buffer, inFormatStr, paramList);
  78.  
  79.     va_end(paramList);
  80.  
  81.     MFASSERT(charsWritten < kMaxOutputTextBuffer);
  82.  
  83.     if (charsWritten < 0)
  84.         result = kMF3DErrCantWrite;
  85.  
  86.     if (result == kMF3DNoErr)
  87.         result = MF3D_WriteProc(inMetafile, charsWritten, buffer);
  88.  
  89.     return result;
  90. }
  91.  
  92. /*==============================================================================
  93.  *    MF3D_WriteTextString
  94.  *
  95.  *    Write a text string
  96.  *==============================================================================
  97.  */
  98. MF3DErr
  99. MF3D_WriteTextString(
  100.     MF3D_FilePtr        inMetafilePtr,
  101.     MF3DCStringPtr        inStringPtr)
  102. {
  103.     MF3DErr                result;
  104.     char                c, *strPtr;
  105.  
  106.     result = kMF3DNoErr;
  107.  
  108.     strPtr = inStringPtr;
  109.  
  110.     /* Output characters until we reach EOS */
  111.     while (result == kMF3DNoErr && (c = *strPtr++) != '\0')
  112.     {    switch (c)
  113.         {    /* These characters are escaped */
  114.             case '\a':    c = 'a'; goto OutputEscape;
  115.             case '\b':    c = 'b'; goto OutputEscape;
  116.             case '\f':    c = 'f'; goto OutputEscape;
  117.             case '\n':    c = 'n'; goto OutputEscape;
  118.             case '\r':    c = 'r'; goto OutputEscape;
  119.             case '\t':    c = 't'; goto OutputEscape;
  120.             case '\v':    c = 'v'; goto OutputEscape;
  121.             case '\\':
  122.             case '\'':
  123.             case '\"':
  124. OutputEscape:
  125.                 result = MF3D_OutputText(inMetafilePtr, kMF3D_StringEscapeStr);
  126.                 /* Fall through to normal output */
  127.             default:
  128.                 if (result == kMF3DNoErr)
  129.                     result = MF3D_OutputText(inMetafilePtr, "%c", c);
  130.         }
  131.     }
  132.  
  133.     return result;
  134. }
  135.  
  136.